<template>
<div class="after-sale-reason views-container">
  <el-dialog @close="saveDialogForm" :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
    <div class="wlm-form" v-if="dialogTableVisible">
      <div class="wlm-form-header wlm-dialog-fixheader">
        <span class="wlm-dialog-inlenr">添加售后原因</span>
      </div>
      <el-scrollbar wrap-class="scrollbar-wrapper">
        <div class="wlm-form-content">
          <div class="wlm-dialog-main">
            <div class="wlm-dialog-content">
              <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
                <el-form-item label="售后原因">
                  <el-input v-model.trim="formFormatData.formData.content">
                  </el-input>
                </el-form-item>
                <el-form-item label="排序">
                  <el-input v-model.trim="formFormatData.formData.sort">
                  </el-input>
                </el-form-item>
                <el-form-item label="是否展示">
                  <el-radio-group v-model="formFormatData.formData.is_show">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
      <el-button size="small" @click="formFormatSubmit" type="primary">保存</el-button>
    </footer>
  </el-dialog>
  <div class="wlm-table">
    <div class="wlm-table-hearder-btn">
      <el-button size="small" type="primary" @click="showdialog(1)">添加原因</el-button>
    </div>
    <div class="wlm-table-header">
      <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
        <el-form-item label="售后原因：" class="search">
          <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.content" placeholder="请输入售后原因" style="width:160px;"></el-input>
        </el-form-item>
        <el-form-item label="" class="filter-btns">
          <el-button type="primary" @click="filesSerch">筛选</el-button>
          <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="wlm-table-content">
      <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column prop="date" label="售后原因" >
          <template slot-scope="scope">
            <span> {{scope.row.content}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="date" label="排序" >
          <template slot-scope="scope">
            <span> {{scope.row.sort}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="是否展示" >
          <template slot-scope="scope">
            <el-switch :active-value="1" :inactive-value="0" @change="changeTableItem({refund_reason_id:scope.row.refund_reason_id,is_show:scope.row.is_show},formFormatData.api.change.is_show)" v-model="scope.row.is_show"> </el-switch>
          </template>
        </el-table-column>

        <el-table-column prop="name" label="添加时间" >
          <template slot-scope="scope">
            <span>{{scope.row.create_time}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" >
          <template slot-scope="scope">
            <div class="operation-group">
              <el-button class="wlm-text" type="text" @click="showdialog(2,scope.row.refund_reason_id)">编辑</el-button>
              <div class="btn-line"></div>
              <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.refund_reason_id)">删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-content flex-row flex-justify-b flex-align-c">
        <el-row class="pagination-btns">
          <el-checkbox class="check-all"  true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
          <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
        </el-row>
        <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
        </el-pagination>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import {
  delRefundReason,
  getRefundReasonList,
  addRefundReason,
  updateRefundReasonInfo,
  getOneRefundReasonInfo
} from '@/api/orders'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'UserPlatform',
  components: {
  },
  created() {
  },
  data() {
    return {
      dialogTableVisible: false,
      selecUseData: [],
      formFormatData: {
        key: 'userForm',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
            api: getOneRefundReasonInfo,
            params: {
              id: ''
            },
            redirect: 'refund_reason_id'
          },
          submitForm: addRefundReason,
          change: {
            is_show: {
              key: 'is_show',
              api: updateRefundReasonInfo
            }
          }
        },
        formData: {
          content: '',
          is_show: 1,
          sort: ''
        },
        rules: {

        }
      },
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getRefundReasonList,
            delList: delRefundReason
          },
          tableData: [],
          files: {
            content: '',
            ids: [],
            checkall: '0',
            Recycle: '1',
            redirect: 'refund_reason_id'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    showdialog(type, params) {
      if (type === 1) {
        this.formFormatData.api.submitForm = addRefundReason
        this.dialogTableVisible = true
      }
      if (type === 2) {
        this.formFormatData.api.submitForm = updateRefundReasonInfo
        this.formFormatDialogEditEvt({ id: params, toggle: 'dialogTableVisible' })
      }
    },
    changeTableCallBack(params) {

    },
    uploadPlatformChange(imgs) {

    },
    saveDialogForm() {
      this.resetDialogFormData({ content: '', is_show: 1, sort: '' })
    }
  }
}
</script>

<style lang="scss" scoped>
.after-sale-reason {
}
</style>
